﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SuperStarProject.Models.PhieuMuaHangModel>" %>
<script type="text/javascript" language"javascript">
    function GetMaDaiLy() {
        var maDaiLy = document.getElementsByName("DaiLyListBox")[0].value;
        document.getElementsByName("MaDaiLy")[0].value = maDaiLy;
    }
    function TinhTien() {
        var diemthuong = parseInt(document.getElementsByName("DiemThuong")[0].value); 
        var soluong = parseInt(document.getElementsByName("SoLuong")[0].value);
        var dongia = parseInt(document.getElementsByName("DonGia")[0].value);
        var tong = soluong * dongia;
        document.getElementsByName("TongTien")[0].value = tong;
        document.getElementsByName("SoLuongMua")[0].value = soluong;
        document.getElementsByName("TongDiemThuong")[0].value = soluong * diemthuong;    
    }
</script>
                <fieldset>
                <legend>Nhập thông tin mua hàng</legend>
                   <% Html.RenderAction("ShowAllDaiLy", "DaiLy");%><br />
                   Số lượng : <select name="SoLuong" id="SoLuong" onchange="TinhTien();">
                    <% for(int i =1; i <= Model.SoLuongMua ;i++)
                        {%>
                            <option value=<%=i%>><%=i%></option>
                    <% }%>
            </select>
                </fieldset>
   <%using (Html.BeginForm("Create","PhieuMuaHang",FormMethod.Post)) {%>
        <%= Html.ValidationSummary(true) %>
            <p>
                <input type="submit" value="Mua hàng và chọn quà" />
            </p>
        <fieldset>         
            <legend>Thông tin phiếu mua hàng</legend>
            <div class="editor-label">
                <%= Html.LabelFor(model => model.MaPhieuMuaHang) %> : 
                <%= Html.TextBoxFor(model => model.MaPhieuMuaHang) %>
            </div>
            
            <div class="editor-label">
                <%= Html.LabelFor(model => model.MaKH) %>
                <%= Html.TextBoxFor(model => model.MaKH) %>
                <%= Html.ValidationMessageFor(model => model.MaKH) %>
            </div>
            
            <div class="editor-label">
                <%= Html.LabelFor(model => model.MaSP) %>
                <%= Html.TextBoxFor(model => model.MaSP) %>
                <%= Html.ValidationMessageFor(model => model.MaSP) %>
            </div>
            
            <div class="editor-label">
                <%= Html.LabelFor(model => model.MaDaiLy) %>
                <%= Html.TextBoxFor(model => model.MaDaiLy) %>
                <%= Html.ValidationMessageFor(model => model.MaDaiLy) %>
            </div>
            
            <div class="editor-label">
                <%= Html.LabelFor(model => model.TongDiemThuong) %>
                <%= Html.TextBoxFor(model => model.TongDiemThuong) %>
                <%= Html.ValidationMessageFor(model => model.TongDiemThuong) %>
            </div>
            
            <div class="editor-label">
                <%= Html.LabelFor(model => model.NgayMua) %>
                <%= Html.TextBoxFor(model => model.NgayMua) %>
                <%= Html.ValidationMessageFor(model => model.NgayMua) %>
            </div>
            

            <%Model.SoLuongMua = 1; %>
            <% Html.HiddenFor(m=>m.SoLuongMua); %>
            <div class="editor-label">
                <%= Html.LabelFor(model => model.SoLuongMua) %>
                <%= Html.TextBoxFor(model => model.SoLuongMua)%>
                <%= Html.ValidationMessageFor(model => model.SoLuongMua)%>
            </div>           
                     
            <div class="editor-label">
                <%= Html.LabelFor(model => model.TongTien) %>
                <%= Html.TextBoxFor(model => model.TongTien)%>
                <%= Html.ValidationMessageFor(model => model.TongTien)%>
            </div> 
            
            Đơn giá :<%=Html.TextBox("DonGia",Model.TongTien.ToString())%>
            Điểm thưởng :<%=Html.TextBox("DiemThuong",Model.TongDiemThuong.ToString())%>
        </fieldset>

    <%} %>
    <div>
        <%= Html.ActionLink("Back to List", "Index") %>
    </div>


